import 'package:flutter/material.dart';

///zhudaihao
///2024-1-30
///基础脚手架
class BaseScaffold extends StatelessWidget {
  ///标题
  final dynamic title;

  /// 右侧按钮
  final List<Widget>? actions;

  ///主页面
  final Widget? body;

  ///是否自己处理返回键
  final Function()? backClick;

  ///是否显示返回按钮图标
  final bool? shownLeading;

  ///背景颜色
  final Color? backgroundColor;

  ///AppBar背景颜色
  final Color? appBarBackgroundColor;

  ///标题是否居中
  final bool? centerTitle;

  ///自定义左边图标
  final Widget? leading;

  ///自定义appbar
  final PreferredSizeWidget? appBar;

  const BaseScaffold(
      {Key? key,
      this.title,
      this.actions,
      this.body,
      this.backClick,
      this.shownLeading,
      this.backgroundColor,
      this.appBarBackgroundColor,
      this.centerTitle,
      this.leading,
      this.appBar})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget titleWidget = Text(
      '$title',
      style: const TextStyle(color: Colors.black, fontSize: 18),
    );
    if (title != null && title is Widget) {
      titleWidget = title;
    }
    return Scaffold(
      backgroundColor: backgroundColor ?? Colors.white,
      resizeToAvoidBottomInset: false,
      appBar: appBar ??
          AppBar(
            //设置背景颜色
            backgroundColor: appBarBackgroundColor ?? Colors.white,
            //标题居中
            centerTitle: centerTitle ?? true,
            //设置阴影
            elevation: 0,
            //设置返回按钮
            leading: leading ??
                Visibility(
                  visible: shownLeading ?? true,
                  child: Row(
                    children: [
                      IconButton(
                        onPressed: () {
                          if (backClick != null) {
                            backClick!();
                          } else {
                            Navigator.pop(context);
                          }
                        },
                        icon: const Icon(
                          Icons.arrow_back_ios_new_outlined,
                          size: 16,
                          color: Colors.black,
                        ),
                      ),
                    ],
                  ),
                ),
            //标题
            title: titleWidget,
            actions: actions,
          ),
      //主题内容
      body: body,
    );
  }
}
